<?php
include 'simple_html_dom.php';
if(isset($_POST['submit']))
{
	$d = $_POST['domain'];
	$domain = 'http://' . $d;
	
	$handle = fopen("http://$d","r");
	$contents2 = '';
	while (!feof($handle)) {
		$contents2 .= fread($handle, 8192);
	}
	
	$html = file_get_html($domain);
	$contents_img = "";
	$i = 0;
	foreach($html->find('img') as $element) {
		
		$i = $i + 1;
		$contents_img .= "#$i: " . $element->src . "<br />";
		
	}
	 
	$contents_link = "";
	$a = 0;
	foreach($html->find('a') as $element) {
		$a = $a + 1;
		$contents_link .= "#$a: " . $element->href . "<br />";
		
	}
}
?>
<html>
<head>
<title>HTML Source Code Viewer</title>
</head>
<body>
	<h2>HTML Source Code Viewer</h2>
	<form method="post" name="pageform" action=""
		onsubmit="return validate(this);">
		<table border="0" style="border-collapse: collapse" width="">
			<tr>
				<td width="" height="91" valign="top">
					<table style="border-collapse: collapse" width="" class="tooltop"
						height="76">
						<tr>
							<td>
								<table border="0" style="border-collapse: collapse" width=""
									cellspacing="5">
									<tr>
										<td height="28" width="100"><font size="2"><b>View source of</b>
										</font><b><font size="2">: </font> </b></td>
										<td height="28" width=""><font size="1">http://</font><input
											type="text" name="domain" size="26"
											value="<?=$_POST['domain']?>"></td>
										<td height="28" width=""><input type="submit" name="submit"
											value="View!" style="float: left"></td>
									</tr>
									<tr>
										<td width="" height="21">&nbsp;</td>
										<td width="" colspan="2" height="21" valign="top"><font
											size="1">(eg. chapagain.com.np)</font></td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>


			<?php
			if(isset($_POST['submit']))
			{
				?>
			<tr>
				<td><textarea rows="10" cols="60" name="code">
				<?=$contents2?>
					</textarea>
				</td>
			</tr>
			<?php
			}
			?>
		</table>
	</form>

	<table>
		<tr>
			<td><b><font color=blue>img tag account: <?=$i?></font></b></td>
		</tr>
		<tr>
			<td><?=$contents_img?></td>
		</tr>
	</table>
	<br />
	<br />
	<table>
		<tr>
			<td><b><font color=blue>link account: <?=$a?></font></b></td>
		</tr>
		<tr>
			<td><?=$contents_link?></td>
		</tr>
	</table>

	<script language="JavaScript">
function validate(theform) {
if (theform.domain.value == "") { alert("No Domain"); return false; }
return true;
}
</script>

</body>
</html>
